package com.nuaa.likesystem.controller;

import com.nuaa.likesystem.common.BaseResponse;
import com.nuaa.likesystem.common.ResultUtils;
import com.nuaa.likesystem.constant.UserConstant;
import com.nuaa.likesystem.model.entity.User;
import com.nuaa.likesystem.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {
    @Resource
    private UserService userService;

    @GetMapping(value = "/login")
    public BaseResponse<User> login(Long userId, HttpServletRequest request) {
        User user = userService.getById(userId);
        request.getSession().setAttribute(UserConstant.USER_LOGIN_STATE, user);
        return ResultUtils.success(user);
    }
}
